home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / jav503.zip / GRAPHAPP.JAV < prev    next >
Text File  |  1996-03-29  |  2KB  |  124 lines

  1. // -[KeepHeading]-
  2.  
  3.  
  4. // -[Copyright]-
  5.  
  6. /**
  7.  * (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights
  8.  * reserved.
  9.  */
  10. import java.lang.*;
  11.  
  12.  
  13. // -[KeepBeforeClass]-
  14. import java.applet.*;
  15. import java.awt.*;
  16.  
  17.  
  18. // -[Class]-
  19.  
  20. /**
  21.  * @jTitle           GraphicsApplet
  22.  * @jOverridability  can be overridden
  23.  * @jDescription
  24.  * Main window of graphics application.
  25.  * 
  26.  * @see              Applet
  27.  */
  28. public 
  29. class GraphicsApplet extends Applet
  30. {
  31. // -[KeepWithinClass]-
  32.  
  33.  
  34. // -[Fields]-
  35.  
  36.  
  37.  
  38. /**
  39.  * Name of the graphics application.
  40.  */
  41. protected String message= new String("Javelin - reach for the sky!");
  42.  
  43.  
  44.  
  45. /**
  46.  * Font used to print message.
  47.  */
  48. protected Font messageFont= new Font("TimesRoman", Font.BOLD|Font.ITALIC, 24);
  49.  
  50. ;
  51.  
  52.  
  53. // -[Methods]-
  54.  
  55. /**
  56.  * Called whenever the mouse button is pressed.
  57.  */
  58. public boolean mouseDown(Event evt, int x, int y)
  59. {
  60.     // Caused paint to be called
  61.     repaint();
  62.  
  63.     return true;
  64. }
  65.  
  66. /**
  67.  * This function is called once at startup for the applet. Here you should
  68.  * do any necessary initialization.
  69.  */
  70. public void init()
  71. {
  72.     resize(400, 300);
  73. }
  74.  
  75. /**
  76.  * Paints the applet window. At this stage it does nothing but in later
  77.  * examples it does.
  78.  */
  79. public void paint(Graphics g)
  80. {
  81.     Rectangle r = bounds();
  82.  
  83.     Color oldColor = g.getColor();
  84.     Font oldFont = g.getFont();
  85.  
  86.     // Paint a blue sky
  87.     g.setColor(Color.blue);
  88.     g.fillRect(0, 0, r.width, r.height);
  89.  
  90.     // Draw some shapes in random positions
  91.     for (int i = 0; i < 10; i++)
  92.     {
  93.         Shape shape = new Circle(
  94.             (int)(Math.random() * r.width),
  95.             (int)(Math.random() * r.height),
  96.             (int)(Math.random() * 30));
  97.  
  98.         shape.show(g);
  99.  
  100.         shape = new Box(
  101.             (int)(Math.random() * r.width),
  102.             (int)(Math.random() * r.height),
  103.             (int)(Math.random() * 100),
  104.             (int)(Math.random() * 40));
  105.  
  106.         shape.show(g);
  107.     }
  108.  
  109.     g.setColor(Color.white);
  110.  
  111.     g.drawString("Click mouse to change scene", 10, 20);
  112.  
  113.     g.setFont(messageFont);
  114.  
  115.     g.drawString(message, 10, 50);
  116.     
  117.     g.setFont(oldFont);
  118.     g.setColor(oldColor);
  119. }
  120.  
  121. }
  122.  
  123.  
  124.